﻿using System.Collections.Generic;
using Navigant.Infrastructure;
using Navigant.Infrastructure.Cases;
using Navigant.Model.PreservationNotices;

namespace Navigant.Model.Custodians
{
    public class CustodianService : CaseService<Custodian>
    {
        private ICase currentCase;
        private IUnitOfWork unitOfWork;
        
        public CustodianService(ICase currentCase)
            : this(currentCase, null, false)
        {
        }

        public CustodianService(ICase currentCase, IUnitOfWork unitOfWork)
            : this(currentCase, unitOfWork, false)
        {
        }

        public CustodianService(ICase currentCase, IUnitOfWork unitOfWork, 
            bool runWithElevatedPrivileges)
            : base(currentCase, unitOfWork, runWithElevatedPrivileges)
        {
            this.currentCase = currentCase;
            this.unitOfWork = unitOfWork;
        }

        public Custodian GetCustodian(int custodianId)
        {
            return this.Repository.FindBy(custodianId);
        }

        public void SaveCustodian(Custodian custodian)
        {
            this.Repository[custodian.Key] = custodian;
        }

        public void RemoveCustodian(Custodian custodian)
        {
            this.Repository.Remove(custodian);
        }

        public IList<Custodian> GetCustodiansBy(PreservationNoticeCriteria criteria)
        {
            return ((ICustodianRepository)this.Repository).FindByCriteria(criteria);
        }

        public IList<Custodian> GetAllCustodiansPaged(int pageSize, int currentPage, 
            int lastItemId, out int itemCount)
        {
            return ((ICustodianRepository)this.Repository).FindAllPaged(pageSize,
                currentPage, lastItemId, out itemCount);
        }

        public IList<Custodian> GetCustodiansBy(string extraCriteriaName, 
            string extraCriteriaValue,bool contains)
        {
            return ((ICustodianRepository)this.Repository).FindByExtraCriteria(extraCriteriaName,
                extraCriteriaValue,contains);
        }

        public IList<string> GetExtraCriteriaPossibleValues(string extraCriteriaFieldName)
        {
            return ((ICustodianRepository)this.Repository).GetExtraCriteriaPossibleValues(extraCriteriaFieldName);
        }

        public string GetDefaultPossibleValue(string extraCriteriaFieldName)
        {
            return ((ICustodianRepository)this.Repository).GetDefaultPossibleValue(extraCriteriaFieldName);
        }

        public void LoadExtendedProperties(Custodian custodian)
        {
            ((ICustodianRepository)this.Repository).LoadExtendedProperties(custodian);
        }
    }
}
